package handler

import (
	"github.com/gin-gonic/gin"
	"github.com/google/uuid"
	"net/http"
	"path/filepath"
)

func Upload(c *gin.Context) {
	file, _ := c.FormFile("file")

	if file == nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 500,
			"msg":  "没有文件",
			"data": nil,
		})
		return
	}
	uuid := uuid.NewString()
	dst := "./upload/upload/" + uuid + filepath.Ext(file.Filename)
	// 上传文件至指定的完整文件路径
	c.SaveUploadedFile(file, dst)

	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "上传成功",
		"data": dst,
	})
}
